/*
 * @Author: Drc
 * @Date: 2021-06-15 14:08:07
 * @LastEditTime: 2021-06-15 18:28:43
 * @LastEditors: Drc
 */

import {supportLocale} from '@path/locale'
import {ThemeType} from '@path/config/theme'
import {createModel} from '@rematch/core'
import {RootModel} from '@path/redux'

interface GLOBAL {
  locale?: supportLocale
  theme?: ThemeType
}

const defaultState: GLOBAL = {
  locale: undefined,
  theme: undefined,
}

const Global = createModel<RootModel>()({
  state: defaultState,
  reducers: {
    setLocale(state: GLOBAL, newLocale: supportLocale): GLOBAL {
      return {
        ...state,
        locale: newLocale,
      }
    },
    setTheme(state: GLOBAL, newTheme: ThemeType): GLOBAL {
      return {
        ...state,
        theme: newTheme,
      }
    },
  },
  effects: {},
})

export default Global
